﻿using BMS.Entity.Dictionary;
using BMS.IRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BMS.Repository
{ 
    public class DictionaryValueRepository:BaseRepository<DictionaryValue>,IDictionaryValueRepository
    {
        private readonly DbContext context;
        public DictionaryValueRepository(DbContext context):base(context)
        {
            this.context = context;
        }
        /// <summary>
        /// 根据ID查询字典项
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public async Task<DictionaryValue> GetDictionaryValueById(int id)
        {
            DictionaryValue value = await context.Set<DictionaryValue>().FirstOrDefaultAsync(m => m.Id == id);
            return value;
        }
        /// <summary>
        /// 根据ID差字典项集合
        /// </summary>
        /// <param name="ids">ID集合</param>
        /// <returns></returns>
        public async Task<List<DictionaryValue>> GetDictionaryValueById(IEnumerable<int> ids)
        {
            List<DictionaryValue> values = new List<DictionaryValue>();
            foreach (int id in ids)
            {
                DictionaryValue value = await context.Set<DictionaryValue>().FirstOrDefaultAsync(m => m.Id == id);
                values.Add(value);
            }
            return values;
        }
        /// <summary>
        /// 根据字典主表ID查询字典从表信息集合
        /// </summary>
        /// <param name="id">主表主键</param>
        /// <returns></returns>
        public async Task<List<DictionaryValue>> GetDictionaryValueByKeyId(int id)
        {
            List<DictionaryValue> values=await context.Set<DictionaryValue>().Where(m=>m.DicKeyId== id).ToListAsync();
            return values;
        }
    }
}
